// http://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html
// ----------------------基于 header 的签名方法------------------------
// PUT /test91883001/dfbdb01d-e7b2-4acb-ad55-c7321d1eb878 HTTP/1.1
// Host: 29.3.91.232:3004
// Accept-Encoding: gzip
// Authorization: AWS4-HMAC-SHA256 Credential=Proxy182kPK0mEu6xY5ix7VnI/20220831/default/s3/aws4_request, SignedHeaders=content-length;content-md5;host;x-amz-content-sha256;x-amz-date, Signature=cc48ef69f014a2484d28e42ae56a1f81a968b63ee00e8897b0ba7720d72f5a90
// Content-Length: 30353
// Content-Md5: 2nusJ65zDQhAm2WxhNi36Q==
// User-Agent: aws-sdk-go/1.43.16 (go1.17.5; linux; amd64)
// X-Amz-Content-Sha256: e4148815d5fb77bef6c6897c824e5e6d6a39d667d56779420c94dc3e9f3202d7
// X-Amz-Date: 20220831T053535Z

// -----------------------基于 chunked 签名的方法-------------------------------
// PUT /test91883001/ExampleChunkedObject.txt HTTP/1.1
// Host: 29.3.91.232:3004
// Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
// Authorization: AWS4-HMAC-SHA256 Credential=Proxy182kPK0mEu6xY5ix7VnI/20220831/default/s3/aws4_request, SignedHeaders=accept;cache-control;content-encoding;content-length;host;pragma;user-agent;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length;x-amz-storage-class, Signature=287a23a1d777128c1e508d28870bd810a654382c1567667fba868051675a561c
// Cache-Control: no-cache
// Content-Encoding: aws-chunked
// Content-Length: 113389
// Pragma: no-cache
// User-Agent: Java/1.8.0_251
// X-Amz-Content-Sha256: STREAMING-AWS4-HMAC-SHA256-PAYLOAD
// X-Amz-Date: 20220831T110853Z
// X-Amz-Decoded-Content-Length: 113124
// X-Amz-Storage-Class: REDUCED_REDUNDANCY

// 拆解 s3 请求头 Authorization
// AWS4-HMAC-SHA256: 这里面包含两个东西：AWS4： scheme； HMAC-SHA256： 标识签名算法ALGORITHM
// scope: /20220831/default/s3/aws4_request, scope中包含 dateStamp=20220831, serviceName = s3, TERMINATOR = aws4_request
// 这个值得是所有参与签名的头
// SignedHeaders=accept;cache-control;content-encoding;content-length;host;pragma;user-agent;x-amz-content-sha256;x-amz-date;x-amz-decoded-content-length;x-amz-storage-class

// 下面说明一下Signature的生成流程
// Signature=287a23a1d777128c1e508d28870bd810a654382c1567667fba868051675a561c
// kSerect = scheme + sk
// kDate = sign(dateStamp, kSecret, "HmacSHA256")
// kRegion = sign(regionName, kDate, "HmacSHA256") // regionName行内就是: default
// kService = sign(serviceName, kRegion, "HmacSHA256") // serviceName: 在scope中
// kSigning = sign(TERMINATOR, kService, "HmacSHA256") // TERMINATOR: 在 scope 中
// signature = sign(stringToSign, kSigning, "HmacSHA256") // stringToSign 生成规则如下

// stringToSign 生成规则
// 需要根据 shceme,ALGORITHM,dateTimeStamp(X-Amz-Date),scope,canonicalRequest生成
// getStringToSign(SCHEME, ALGORITHM, dateTimeStamp, scope, canonicalRequest)

// canonicalRequest 生成规则，
// httpMethod + "\n" +
// 	getCanonicalizedResourcePath(endpoint) + "\n" +
//	queryParameters + "\n" +
//	canonicalizedHeaders + "\n" +
//	canonicalizedHeaderNames + "\n" +
//	bodyHash; // 来自请求头:X-Amz-Content-Sha256

// ====== 签名算法: sign(String stringData, byte[] key, String algorithm) java实现  ======
// byte[] data = stringData.getBytes("UTF-8");
// Mac mac = Mac.getInstance(algorithm);
// mac.init(new SecretKeySpec(key, algorithm));
// return mac.doFinal(data);

// 预签名算法
// PUT /golang-admin-test-01/upload-threshold-file?uploadId=2~ILha0lKeC3mcb1ux2-n5Tq6B2pmelN_%3A%3A2~rZAncA-158VdVorjZwnRD8CmDQ8zOFm&partNumber=1
// &X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20230725T031806Z&X-Amz-SignedHeaders=host
// &X-Amz-Expires=8640&X-Amz-Credential=ProxyxvKlanLkjDMdgAlj7VVD%2F20230725%2FDEFAULT%2Fs3%2Faws4_request
// &X-Amz-Signature=d4ce9f5d4a3fe4bf122883ed051ce6db5f0b27c0e208b3ae00c0f06d2070a1d6 HTTP/1.1
// Host: 29.3.91.232:3001
// Accept-Encoding: gzip,deflate
// Content-Length: 5242880
// User-Agent: Apache-HttpClient/4.5.11 (Java/17.0.2)
// X-Forwarded-For: 22.6.52.56
// 预签名算法关注点：
package signature
